#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define XH(i,a,b) for(int i = a; i < b; ++i)
#define XXH(i,b,a) for(int i = b - 1; i >= a; --i)
#define Module 998244353
int tInt;ll tll;string tString;char tChar;
vector<int>tIVector;

int n,t;

void solve(){
  int numTleft = 0, numTright = 0;
  XH(i,0,n){
    if(tString[i] == 'T'){
      numTright++;
    }
  }
  if(numTright != n/3*2)cout<<"NO"<<endl;
  else{
    XH(i,0,n){
      if(tString[i] == 'T'){
        numTleft++;
      }else{
        numTleft--;
        if(numTleft<0){
          printf("NO\n");
          return;
        }
      }
    }
    numTright = 0;
    XXH(i,n,0){
      if(tString[i] == 'T'){
        numTright++;
      }else{
        numTright--;
        if(numTright<0){
          printf("NO\n");
          return;
        }
      }
    }
    cout<<"YES"<<endl;
  }
}

int main(){
  #ifndef ONLINE_JUDGE
    auto start_clock = clock();
    //freopen("input.txt","r",stdin);
//  freopen("output.txt","w",stdout);
  #endif
  cin>>t;
  XH(i,0,t){
    cin>>n;
    cin>>tString;
    solve();
  }
  
  #ifndef ONLINE_JUDGE
    auto end_clock = clock();
    //cout<<"runtime: "<<end_clock - start_clock<<"ms"<<endl;
  #endif
  return 0;
}
